﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BLL;
using DAL;
namespace 健身房管理
{
    public partial class UGoods : UserControl
    {
        UgoodsBLL ugl = new UgoodsBLL();
        DBHelper db = new DBHelper();
        public UGoods()
        {
            InitializeComponent();
        }


        private void UGoods_Load(object sender, EventArgs e)
        {
            jiaz();
        }
        public void jiaz()
        {
           
            this.guna2DataGridView1.AutoGenerateColumns = false;
            DataTable dt = ugl.showUgoods();
            this.guna2DataGridView1.DataSource = dt;

        }

        private void guna2DataGridView1_Click(object sender, EventArgs e)
        {
            DataTable dt= ugl.showUgoods();
            //int id = int.Parse(this.);
            this.label6.Text = dt.Rows[0]["goodsnum"].ToString();
            this.label5.Text= dt.Rows[0]["goodsprice"].ToString();
            this.label2.Text= dt.Rows[0]["goodsname"].ToString();
        }

        private void guna2Button1_Click(object sender, EventArgs e)
        {
            int id=int.Parse(this.guna2DataGridView1.CurrentRow.Cells["id"].Value.ToString());
            string sql = string.Format("select * from Goods where id='{0}'", id);
            DataTable dt = db.cx(sql);
            int b = int.Parse(dt.Rows[0]["goodsnum"].ToString());
            int a =int.Parse(this.guna2TextBox1.Text);
            int c = b - a;
            Boolean bl = ugl.up(c, id);
            if (bl)
            {
                MessageBox.Show("成功");
            }
            else {
                MessageBox.Show("失败");
            }
        }
    }
}